package greddy;

public class _10_860_柠檬水找零 {
    public static boolean lemonadeChange(int[] bills) {
    	int five = 0;
    	int ten = 0;
    	int tw = 0;
    	for(int i = 0; i < bills.length; i++) {
    		if(bills[i] == 5) {
    			five++;
    		} else if(bills[i] == 10) {
    			ten++;
    			five--;
    		} else {
    			tw++;
    			five--;
    			if(ten == 0) {
    				five -= 2;
    			} else {
    				ten--;
    			}
    		}
    		if(five < 0 || ten < 0 || tw < 0) {
    			return false;
    		}
    	}
    	
    	return true;
    }
    
    public static void main(String[] args) {
    	int[] bills = {5,5,10,20,5,5,5,5,5,5,5,5,5,10,5,5,20,5,20,5};
    	System.out.println(lemonadeChange(bills));
	}
}
